package com.ht.web.aduit;

import com.ht.bean.aduit.Aduitlog;
import com.ht.bean.aduit.Checkq;
import com.ht.bean.emp.Dep;
import com.ht.bean.emp.Empinfo;
import com.ht.bean.json.JsonData;
import com.ht.service.aduit.CheckqService;
import com.ht.service.emp.DepService;
import com.ht.util.Contants;
import com.ht.util.Pager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 * @author 王金宝
 * @date 2020/6/29 20:08
 */
@Controller
@RequestMapping("aduitcheck")
public class AduitCheckController {
    @Resource
    private JsonData jsonData;
    @Resource
    private CheckqService checkqService;
    @Resource
    private DepService depService;

    //去到未打卡说明管理页面
    @RequestMapping("checkqlist")
    public String modellist(){
        return "aduit/aduitchecklist";
    }

    /**
     * @param limit
     * @param page
     * @return
     * 获取未打卡列表信息
     */
    @RequestMapping("listdata")
    @ResponseBody
    public JsonData depList(int limit , int page, HttpSession session){
        Pager pager = new Pager();
        pager.setPageSize(limit);
        pager.setCurrPage(page);
        Empinfo empinfo = (Empinfo) session.getAttribute("user");
        Dep dep = depService.getDepByEmpid(empinfo.getEmp_id());
        if(dep != null){
            if(dep.getParentid() == 0){
                jsonData.setCount(checkqService.getAduitCheckRow2(Contants.ADUIT_NOT,dep.getDepid()));
                jsonData.setData(checkqService.getAduitCheck2(pager,Contants.ADUIT_NOT,dep.getDepid()));
            }else {
                jsonData.setCount(checkqService.getAduitCheckRow(empinfo.getEmp_id(), Contants.ADUIT_NOT,dep.getDepid()));
                jsonData.setData(checkqService.getAduitCheck(pager,empinfo.getEmp_id(), Contants.ADUIT_NOT,dep.getDepid()));
            }
        }else {
            jsonData.setData(null);
        }
        return jsonData;
    }


    @RequestMapping("toaduit")
    public String toupd(Integer id, Map map){
        Checkq checkq = checkqService.selectByPrimaryKey(id);
        map.put("check",checkq);
        return "aduit/aduitcheck";
    }

    @RequestMapping("aduit")
    @ResponseBody
    public Boolean add(Checkq checkq, HttpSession session){
        //设置要获取到什么样的时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        //获取String类型的时间
        String createdate = sdf.format(new Date());
        checkq.setAudittime(createdate);
        Empinfo empinfo = (Empinfo) session.getAttribute("user");
        checkq.setAuditperson(empinfo.getEmp_name());
        int b = checkqService.updateByPrimaryKeySelective(checkq);
        if(b>0){
            return true;
        }
        return false;
    }
}
